<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>工作调度-工作调度模板</title>
    <link rel="stylesheet" href="/layui/v11/css/layui.css">
    <style>
        /* 强制多选项横向排列 */
        .layui-form-checkbox {
            display: inline-block;
            margin-right: 15px;
        }

        /* 输入框单独成行 */
        .layui-input-block > .layui-input {
            display: block;
            margin-top: 5px;
        }

        /* 单选组全局样式 */
        .layui-form-radio {
            margin-right: 5px !important;
        }

        .layui-form-radio > div {
            white-space: nowrap; /* 防止文字换行 */
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <div class="layui-card-body">
                    <!--设置模板-->
                    <div class="panel panel-default operation" hidden>
                        <div class="panel-heading title"></div>
                        <form class="layui-form" action="" lay-filter="info">
                            <label for="_id"></label>
                            <input id="_id" name="id" hidden/>
                            <fieldset class="layui-elem-field layui-field-title">
                                <legend>模板信息</legend>
                            </fieldset>
                            <div class="layui-form-item">
                                <label class="layui-form-label">标题</label>
                                <div class="layui-input-inline">
                                    <label for="surveyTitle"></label>
                                    <input id="surveyTitle" name="surveyTitle" placeholder="请输入模板标题"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <fieldset class="layui-elem-field layui-field-title">
                                <legend>模板问题内容</legend>
                            </fieldset>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline">
                                    <div class="layui-btn" onclick="addSurveyContent_1()">增加文本问题</div>
                                </div>
                                <div class="layui-input-inline">
                                    <div class="layui-btn" onclick="addSurveyContent_2()">增加多选问题</div>
                                </div>
                                <div class="layui-input-inline">
                                    <div class="layui-btn" onclick="addSurveyContent_3()">增加单选问题</div>
                                </div>
                            </div>
                            <div id="_addSurveyContentDiv">
                                <div id="_addSurveyContent"></div>
                            </div>
                            <fieldset class="layui-elem-field layui-field-title">
                                <legend>生成模板</legend>
                            </fieldset>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">生成模板
                                    </button>
                                    <button class="layui-btn layui-btn-primary" onclick="btn_cancel()">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!--查看模板信息-->
                    <div class="panel panel-default operation1" hidden>
                        <div class="panel-heading title"></div>
                        <div class="layui-card-body">
                            <form class="layui-form " action="" lay-filter="info" style="margin-top: 10px">
                                <fieldset class="layui-elem-field layui-field-title">
                                    <legend>模板信息</legend>
                                </fieldset>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">标题</label>
                                    <div class="layui-input-block">
                                        <label for="viewTitle"></label>
                                        <input id="viewTitle" autocomplete="off" class="layui-input" readonly>
                                    </div>
                                </div>
                                <fieldset class="layui-elem-field layui-field-title">
                                    <legend>模板问题内容</legend>
                                </fieldset>
                                <div id="viewSurvey"></div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn layui-btn-primary" onclick="btn_cancel()">返回</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!--首页查询-->
                    <div class="table_div">
                        <div class="layui-form-item">
                            <div class="layui-input-inline">
                                <label for="key"></label>
                                <input type="text" id="key" class="layui-input" autocomplete="off"
                                       placeholder="请输入模板标题">
                            </div>
                            <div class="layui-input-inline ">
                                <button class="layui-btn" onclick="search()" id="search">查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="resetSearch()" id="reset-btn">
                                    重置
                                </button>
                            </div>
                        </div>
                        <table class="layui-table" id="showTable" lay-filter="showTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--模板添加按钮-->
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加模板</button>
    </div>
</script>
<!--模板状态-->
<script type="text/html" id="tool">
    {{#  if(d.state == '0'){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="push">发布</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="view">查看</a>
    {{#  }else { }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="view">查看</a>
    {{#  } }}
</script>
</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var _xh = 0;
    var _surveyArr = [];
    layui.use(['table', 'layer', 'laydate'], function () {
        //日期
        laydate.render({
            elem: '#date'
        });
        //加载table
        tableIns1 = table.render({
            elem: '#showTable',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            page: true //开启分页
            ,
            url: '/workflow/log/survey/queryGzddmb' //数据接口
            ,
            method: 'POST',
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null
                        : res.data.records
                    //解析数据列表
                }
            },
            cols: [[{
                align: 'center',
                width: 530,
                field: 'title',
                title: '模板标题',
                sort: true
            }, {
                align: 'center',
                width: 190,
                field: 'createTime',
                title: '模板创建日期',
                sort: true,
                templet: function (d) {
                    // 格式化日期为 'yyyy-MM-dd'
                    return layui.util.toDateString(d.create_time, 'yyyy-MM-dd');
                }
            }, {
                align: 'center',
                width: 240,
                toolbar: "#tool",
                fixed: 'right',
                title: '操作'
            }]],

            toolbar: '#toolbar'
        });
        //表头工具
        table.on('toolbar(showTable)', function (obj) {
            switch (obj.event) {
                case 'batchDeleted':
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    if (data.length == 0) {
                        layer.msg("请选择要批量删除的列");
                    } else {
                        var ids = [];
                        $(data).each(function (index, item) {
                            ids.push(item.id);
                        });
                        tipDialog(ids);
                    }
                    break;
                case 'add':
                    $(".table_div").hide();
                    $(".operation").show();
                    $(".title").html("新增模板");
                    $("#_addSurveyContentDiv").html("<div id='_addSurveyContent'></div>");
                    $(".operation input[name=id]").val("");
                    $(".operation input[name=surveyTitle]").val("");
                    _xh = 0;
                    _surveyArr = [];
                    break;
            }
        });
        //列操作
        table.on('tool(showTable)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    var ids = [];
                    ids.push(data.id);
                    tipDialog(ids);
                    break;
                case 'push':
                    var ids = [];
                    ids.push(data.id);
                    tipPushlog(ids);
                    break;
                case 'edit':
                    $(".table_div").hide();
                    $(".operation").show();
                    $(".title").html("修改模板");
                    $("#_addSurveyContentDiv").html("<div id='_addSurveyContent'></div>");
                    $(".operation input[name=id]").val(data.id);
                    $(".operation input[name=surveyTitle]").val(data.title);
                    // var contentSurveyJson = eval("(" + data.content + ")");
                    var contentSurveyJson = JSON.parse(data.content);
                    _surveyArr = contentSurveyJson;
                    // arr 对象转list
                    for (var ii = 0; ii < _surveyArr.length; ii++) {
                        var optionsArr = _surveyArr[ii].options;
                        var _optionsArr = [];
                        for (var _ii in optionsArr) {
                            _optionsArr.push(optionsArr[_ii]);
                        }
                        _surveyArr[ii].options = _optionsArr;
                    }
                    _xh = contentSurveyJson.length;
                    // $("#_addSurveyContent").html("");
                    var tmp = "";
                    for (var i = 0; i < contentSurveyJson.length; i++) {
                        var _optionsType = contentSurveyJson[i].optionsType;
                        var _optionsTitle = contentSurveyJson[i].optionsTitle;
                        var optionsArr = contentSurveyJson[i].options;

                        if (_optionsType == "1") {
                            // 文本
                            tmp += "<div id='wj_" + i + "'>"
                                + "<div class='layui-form-item'>"
                                + "<label class='layui-form-label'>文本问题</label>"
                                + "<div class='layui-input-inline'>"
                                + "<input onkeyup='javascript:insertArry(this, " + i + ");' id='wjnrId_" + i + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input' value='" + _optionsTitle + "'>"
                                + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteOptions(" + i + ")'>删除</a>";

                            if (optionsArr[0] == "date") {
                                tmp += "<div onclick='dateOptions(" + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox layui-form-checked' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>"
                            } else {
                                tmp += "<div onclick='dateOptions(" + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                            }

                            tmp += "<a>日期类型</a>"
                                + "</div>"
                                + "</div>"
                                + "</div>";

                        } else if (_optionsType == "2") {
                            // 多选
                            tmp += "<div id='wj_" + i + "'>"
                                + "<div class='layui-form-item'>"
                                + "<label class='layui-form-label'>多选问题</label>"
                                + "<div class='layui-input-inline'>"
                                + "<input onkeyup='javascript:insertArry(this, " + i + ");' id='wjnrId_" + i + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input' value='" + _optionsTitle + "'>"
                                + "<a style='cursor:pointer' onclick='deleteOptions(" + i + ")'>删除</a>"
                                + "</div>"
                                // + "<label class='layui-form-label'></label>"
                                + "<div class='layui-input-inline'>"
                                + "<div class='layui-btn layui-btn-danger layui-btn-xs' onclick='addWjnrxx(" + i + ")'>增加多选</div>"
                                + "</div>"
                                + "<div class='layui-form-item'>"
                                + "<label id='options_" + i + "' style='line-height: 60px' class='layui-form-label'>选项</label>"

                            // 遍历处理 optionsArr
                            for (var _i in optionsArr) {
                                var _t = optionsArr[_i][0];
                                var _f = optionsArr[_i][1];

                                tmp += "<div class='layui-input-inline' id='optionsDiv_" + i + "_" + _i + "'>"
                                    + "<input onkeyup='javascript:insertArry1(this, " + i + ", " + _i + ");' id='wjnrxxId_" + i + "' name='wjnrxxName' placeholder='请输入选项' autocomplete='off' class='layui-input' value='" + _t + "'>"
                                    + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteoptions(" + _i + "," + i + ")'>删除</a>";
                                if (_f) {
                                    tmp += "<div onclick='inputOptions(" + _i + "," + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox layui-form-checked' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                                } else {
                                    tmp += "<div onclick='inputOptions(" + _i + "," + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                                }
                                tmp += "<a>文本框选项</a>"
                                    + "</div>";
                            }

                            +"</div>"
                            + "</div>"
                            + "</div>";
                            // 	遍历处理 optionsArr

                        } else if (_optionsType == "3") {
                            // 单选
                            tmp += "<div id='wj_" + i + "'>"
                                + "<div class='layui-form-item'>"
                                + "<label class='layui-form-label'>单选问题</label>"
                                + "<div class='layui-input-inline'>"
                                + "<input onkeyup='javascript:insertArry(this, " + i + ");' id='wjnrId_" + i + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input' value='" + _optionsTitle + "'>"
                                + "<a style='cursor:pointer' onclick='deleteOptions(" + i + ")'>删除</a>"
                                + "</div>"
                                // + "<label class='layui-form-label'></label>"
                                + "<div class='layui-input-inline'>"
                                + "<div class='layui-btn layui-btn-danger layui-btn-xs' onclick='addWjnrxx(" + i + ")'>增加单选</div>"
                                + "</div>"
                                + "<div class='layui-form-item'>"
                                + "<label id='options_" + i + "' style='line-height: 60px' class='layui-form-label'>选项</label>"

                            // 遍历处理 optionsArr
                            for (var _i in optionsArr) {
                                var _t = optionsArr[_i][0];
                                var _f = optionsArr[_i][1];

                                tmp += "<div class='layui-input-inline' id='optionsDiv_" + i + "_" + _i + "'>"
                                    + "<input onkeyup='javascript:insertArry1(this, " + i + ", " + _i + ");' id='wjnrxxId_" + i + "' name='wjnrxxName' placeholder='请输入选项' autocomplete='off' class='layui-input' value='" + _t + "'>"
                                    + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteoptions(" + _i + "," + i + ")'>删除</a>";
                                if (_f) {
                                    tmp += "<div onclick='inputOptions(" + _i + "," + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox layui-form-checked' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                                } else {
                                    tmp += "<div onclick='inputOptions(" + _i + "," + i + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>";
                                }
                                tmp += "<a>文本框选项</a>"
                                    + "</div>";
                            }
                            +"</div>"
                            + "</div>"
                            + "</div>";
                        }
                    }
                    $("#_addSurveyContent").html(tmp);
                    break;
                case 'view':
                    $(".table_div").hide();
                    $(".operation").hide();
                    $(".operation1").show();
                    var contentSurveyJson = eval("(" + data.content + ")");
                    $("#viewTitle").val(data.title);
                    var viewSurveyTmp = "";
                    for (var i = 0; i < contentSurveyJson.length; i++) {
                        var _optionsType = contentSurveyJson[i].optionsType;
                        var _optionsTitle = contentSurveyJson[i].optionsTitle;
                        viewSurveyTmp += "<div class='layui-form-item'>";
                        if (_optionsType == "1") {
                            // 文本
                            viewSurveyTmp += "<label class='layui-form-label' style='width: 300px;float: left'>" + _optionsTitle + "</label>"
                                + "<div class='layui-input-block'>"
                                + "<input type='text' placeholder='请输入' autocomplete='off' class='layui-input' style='width: 500px'>"
                                + "</div>";
                        } else if (_optionsType == "2") {
                            // 多选
                            // 多选（修正版）
                            viewSurveyTmp += "<label class='layui-form-label' style='width: 300px'>" + _optionsTitle + "</label>"
                                + "<div class='layui-input-block'>";
                            var _options = contentSurveyJson[i].options;
                            for (var _i in _options) {
                                viewSurveyTmp += "<div class='layui-unselect layui-form-checkbox' lay-skin='primary'>"
                                    + "<span>" + _options[_i][0] + "</span>"
                                    + "<i class='layui-icon layui-icon-ok'></i>"
                                    + "</div>";

                                if (_options[_i][1]) {
                                    viewSurveyTmp += "<input type='text' class='layui-input' style='margin-left: 30px'>";
                                }
                            }
                            viewSurveyTmp += "</div>";
                        } else if (_optionsType == "3") {
                            // 单选（横向排列修正版）
                            viewSurveyTmp += "<label class='layui-form-label' style='width: 300px'>" + _optionsTitle + "</label>"
                                + "<div class='layui-input-block' style='display: flex; flex-wrap: wrap; align-items: center;'>"; // 关键修改点

                            var _options = contentSurveyJson[i].options;
                            for (var _i in _options) {
                                var flag = _options[_i][1];

                                // 单选项容器（新增外层包裹）
                                viewSurveyTmp += "<div style='margin-right: 20px; display: flex; align-items: center;'>"
                                    + "<div class='layui-unselect layui-form-radio' title='" + _options[_i][0] + "'>"
                                    + "<i class='layui-anim layui-icon layui-icon-radio'></i>"
                                    + "<div style='margin-left: 5px'>" + _options[_i][0] + "</div>"
                                    + "</div>";

                                // 关联输入框（独立成行）
                                if (flag) {
                                    viewSurveyTmp += "<input type='text' class='layui-input' style='margin-left: 10px; width: 120px'>";
                                }

                                viewSurveyTmp += "</div>"; // 关闭容器
                            }
                            viewSurveyTmp += "</div></div>"; // 闭合layui-input-block和form-item
                        }
                        viewSurveyTmp += "</div>";
                    }
                    $("#viewSurvey").html(viewSurveyTmp);
                    break;
            }
        });
        //删除
        var tipDialog = function (ids) {
            layer.open({
                content: "确定要删除么?",
                yes: function (index) {
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                    CoreUtil.sendDelete("/workflow/log/survey/removeGzddmb", ids, function (res) {
                        layer.msg(res.msg, {
                            time: 1000
                        }, function () {
                            search();
                        });
                    });
                }
            });
        };
        //发布
        var tipPushlog = function (ids) {
            layer.open({
                content: "确定要发布么?",
                yes: function (index, layero) {
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                    CoreUtil.sendDelete("/workflow/log/survey/pushGzddmb", ids, function (res) {
                        layer.msg(res.msg, {
                            time: 1000
                        }, function () {
                            search();
                        });
                    });
                }
            });
        };


        //监听保存
        form.on('submit(submit)', function (data) {
            const surveyTitle = $("#surveyTitle").val();
            const _id = $("#_id").val();
            if (CoreUtil.isEmpty(surveyTitle)) {
                layer.msg("模板标题未填写，请填写!");
                return false;
            }
            const _obj = [];
            if (_surveyArr.length > 0) {
                for (var i in _surveyArr) {
                    var map = {};
                    var optionsTitle = _surveyArr[i].optionsTitle;
                    if (CoreUtil.isEmpty(optionsTitle)) {
                        layer.msg("存在未填写的模板选项标题，请填写!");
                        return false;
                    }
                    var optionsType = _surveyArr[i].optionsType;
                    var _servey = {};
                    map["optionsTitle"] = optionsTitle;
                    map["optionsType"] = optionsType;
                    var optionsArr = _surveyArr[i].options;
                    var _options = {};
                    if (optionsType != "1") {
                        // 处理选择类的
                        if (optionsArr.length > 0) {
                            for (var _i in optionsArr) {
                                if (CoreUtil.isEmpty(optionsArr[_i])) {
                                    layer.msg("存在未填写的模板问题选项，请填写!");
                                    return false;
                                } else {
                                    _options[_i] = optionsArr[_i];
                                }
                            }
                        } else {
                            layer.msg("存在未添加的模板问题选项，请添加!");
                            return false;
                        }
                    } else {
                        // 处理文本类的
                        if (optionsArr.length > 0) {
                            for (var _i in optionsArr) {
                                if (CoreUtil.isEmpty(optionsArr[_i])) {
                                } else {
                                    _options[_i] = optionsArr[_i];
                                }
                            }
                        }
                    }
                    map["options"] = _options;
                    _obj.push(map);
                }
            } else {
                layer.msg("还是设置模板问题，请添加!");
                return false;
            }
            console.log(JSON.stringify(_obj));
            var mapArr = {
                'id': _id,
                'surveyTitle': surveyTitle,
                'optionsConent': JSON.stringify(_obj),
            };
            CoreUtil.sendPost("/workflow/log/survey/saveGzddmb", mapArr, function (res) {
                if (res.code == 0) {
                    $(".table_div").show();
                    $(".operation").hide();
                    search();
                } else {
                    layer.msg(res.msg);
                    return false;
                }

            });

            return false;
        });
    });

    //执行查询
    function search() {
        //这里以搜索为例
        tableIns1.reload({
            where: { //设定异步数据接口的额外参数，任意设
                title: $("#key").val()
            },
            page: {
                curr: 1
                //重新从第 1 页开始
            }
        });
    }

    // 重置按钮的点击事件
    function resetSearch() {
        // 获取id为key的input元素
        var inputElement = document.getElementById('key');
        // 设置输入框的内容为初始值
        inputElement.value = ' ';  // 这里是你想要重置为的初始值
    }

    // 增加文本框
    function addSurveyContent_1() {
        var surveyOptionsArr = {};
        surveyOptionsArr["options"] = [];
        _surveyArr[_xh] = surveyOptionsArr;
        _surveyArr[_xh]['optionsType'] = "1";
        var xh = _surveyArr.length - 1;
        var tmp = "";
        tmp += "<div id='wj_" + xh + "'>"
            + "<div class='layui-form-item'>"
            + "<label class='layui-form-label'>文本问题</label>"
            + "<div class='layui-input-inline'>"
            + "<input onkeyup='javascript:insertArry(this, " + xh + ");' id='wjnrId_" + xh + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input'>"
            + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteOptions(" + xh + ")'>删除</a>"
            + "<div onclick='dateOptions(" + xh + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>"
            + "<a>日期类型</a>"
            + "</div>"
            + "</div>"
            + "</div>";
        _xh++;
        $("#_addSurveyContent").after(tmp);
    }

    // 增加多选框
    function addSurveyContent_2() {
        var surveyOptionsArr = {};
        surveyOptionsArr["options"] = [];
        _surveyArr[_xh] = surveyOptionsArr;
        _surveyArr[_xh]['optionsType'] = "2";

        // var xh = _xh;
        var xh = _surveyArr.length - 1;
        var tmp = "";
        tmp += "<div id='wj_" + xh + "'>"
            + "<div class='layui-form-item'>"
            + "<label class='layui-form-label'>多选问题</label>"
            + "<div class='layui-input-inline'>"
            + "<input onkeyup='insertArry(this, " + xh + ");' id='wjnrId_" + xh + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input'>"
            + "<a style='cursor:pointer' onclick='deleteOptions(" + xh + ")'>删除</a>"
            + "</div>"
            // + "<label class='layui-form-label'></label>"
            + "<div class='layui-input-inline'>"
            + "<div class='layui-btn layui-btn-danger layui-btn-xs' onclick='addWjnrxx(" + xh + ")'>增加多选</div>"
            + "</div>"
            + "<div class='layui-form-item'>"
            + "<label id='options_" + xh + "' style='line-height: 60px' class='layui-form-label'>选项</label>"
            + "</div>"
            + "</div>"
            + "</div>";
        _xh++;

        $("#_addSurveyContent").after(tmp);

    }

    // 增加单选框
    function addSurveyContent_3() {
        var surveyOptionsArr = {};
        surveyOptionsArr["options"] = [];
        _surveyArr[_xh] = surveyOptionsArr;
        _surveyArr[_xh]['optionsType'] = "3";

        // var xh = _xh;
        var xh = _surveyArr.length - 1;
        var tmp = "";
        tmp += "<div id='wj_" + xh + "'>"
            + "<div class='layui-form-item'>"
            + "<label class='layui-form-label'>单选问题</label>"
            + "<div class='layui-input-inline'>"
            + "<input onkeyup='insertArry(this, " + xh + ");' id='wjnrId_" + xh + "' name='wjnrName' placeholder='请输入问题' autocomplete='off' class='layui-input'>"
            + "<a style='cursor:pointer' onclick='deleteOptions(" + xh + ")'>删除</a>"
            + "</div>"
            // + "<label class='layui-form-label'></label>"
            + "<div class='layui-input-inline'>"
            + "<div class='layui-btn layui-btn-danger layui-btn-xs' onclick='addWjnrxx(" + xh + ")'>增加单选</div>"
            + "</div>"
            + "<div class='layui-form-item'>"
            + "<label id='options_" + xh + "' style='line-height: 60px' class='layui-form-label'>选项</label>"
            + "</div>"
            + "</div>"
            + "</div>";
        _xh++;

        $("#_addSurveyContent").after(tmp);

    }

    // 增加文件内容信息
    function addWjnrxx(xh) {
        var tmp = "";
        var _surveyOptionsArr = _surveyArr[xh];
        var _wjnrxxArry = {};
        if (_surveyOptionsArr.options.length >= 16) {
            layer.msg("模板内容选择框最多新增16条");
            return false;
        }
        var _optionsArr = _surveyOptionsArr["options"];
        _optionsArr.push(_wjnrxxArry);
        var _xxxh = _optionsArr.length - 1;
        tmp += "<div class='layui-input-inline' id='optionsDiv_" + xh + "_" + _xxxh + "'>"
            + "<input onkeyup='insertArry1(this, " + xh + ", " + _xxxh + ");' id='wjnrxxId_" + xh + "' name='wjnrxxName' placeholder='请输入选项' autocomplete='off' class='layui-input'>"
            // + "<a style='cursor:pointer;margin-left:5px' onclick='deleteoptions("+_xxxh+","+xh+")'>增加选项文本</a>"
            + "<a style='cursor:pointer;margin-right:20px;' onclick='deleteoptions(" + _xxxh + "," + xh + ")'>删除</a>"
            + "<div onclick='inputOptions(" + _xxxh + "," + xh + ",this)' style='margin-top:-1px;margin-right:-7px' class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon layui-icon-ok'></i></div>"
            + "<a>文本框选项</a>"
            + "</div>"
        $("#options_" + xh + "").after(tmp);
    }

    //删除
    function deleteOptions(xh) {
        _surveyArr.splice(xh, 1);
        $("#wj_" + xh + "").remove();
    }

    //删除
    function deleteoptions(xxxh, xh) {
        var _surveyOptionsArry = _surveyArr[xh];
        var _optionsArry = _surveyOptionsArry["options"]
        _optionsArry.splice(xxxh, 1);
        $("#optionsDiv_" + xh + "_" + xxxh + "").remove();
    }

    // 时间选择
    function dateOptions(xh, that) {
        // 1. 获取数据引用
        var surveyItem = _surveyArr[xh];

        // 2. 提前检查问题内容
        if (CoreUtil.isEmpty(surveyItem.optionsTitle)) {
            layer.msg("请先填写问题内容！");
            return false;
        }

        // 3. 切换状态
        var isChecked = $(that).hasClass('layui-form-checked');

        // 4. 更新UI状态
        $(that).toggleClass('layui-form-checked');

        // 5. 更新数据状态
        if (!isChecked) {
            // 设置为日期类型
            surveyItem.options = ["date"];  // 更规范的标记方式
            surveyItem.isDate = true;      // 建议新增这个字段
        } else {
            // 取消日期类型
            surveyItem.options = [""];
            surveyItem.isDate = false;
        }

        // 6. 更新输入框类型（可选）
        var input = $('#wjnrId_' + xh);
        input.attr('type', isChecked ? 'text' : 'date');
    }

    //
    function inputOptions(xxxh, xh, that) {
        // layui-unselect layui-form-checkbox layui-form-checked // 选中
        // layui-unselect layui-form-checkbox // 未选中
        var i = _surveyArr[xh].options[xxxh].length;
        var className = that.className;
        if (className.includes("layui-form-checked")) {
            // 取消选中
            $(that)[0].className = 'layui-unselect layui-form-checkbox'
            var _surveyOptionsArr = _surveyArr[xh];
            var _wjnrxxArry = _surveyOptionsArr['options'];
            // var xxxhArr = new Array();
            // xxxhArr.push(false);
            _wjnrxxArry[xxxh][1] = false;
        } else {
            // 选中
            if (i == 0) {
                layer.msg("请先选项填写内容！");
                return false;
            } else {
                $(that)[0].className = 'layui-unselect layui-form-checkbox layui-form-checked'
            }
            var _surveyOptionsArr = _surveyArr[xh];
            var _wjnrxxArry = _surveyOptionsArr['options'];
            // var xxxhArr = new Array();
            // xxxhArr.push(true);
            _wjnrxxArry[xxxh][1] = true;
        }
        console.log(xxxh + "," + xh);
    }

    //
    function insertArry(obj, xh) {
        // console.log("_surveyArrXh："+xh);
        // 在数据组记录
        var _surveyContentArr = _surveyArr[xh];
        _surveyContentArr["optionsTitle"] = obj.value;
    }

    //
    function insertArry1(obj, xh, xxxh) {
        // console.log("_surveyArrXh："+xh + ";xxxh：" + xxxh);
        // 在数据组记录
        var _surveyOptionsArr = _surveyArr[xh];
        var _wjnrxxArry = _surveyOptionsArr['options'];
        var xxxhArr = [];
        xxxhArr.push(obj.value);
        _wjnrxxArry[xxxh] = xxxhArr;
    }

    //返回
    function btn_cancel() {
        $(".table_div").show();
        $(".operation").hide();
        return false;
    }
</script>